using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class webadmin_controls_ntv_edit_info : System.Web.UI.UserControl
{
    string sql = "";
    public Common comm = new Common();
    public string id;
    public DataTable dtt;
    public string mess = "";
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            LoadTP();
            LoadQG();
            LoadDT();
            LoadSK();
            sql = "SELECT ConNguoi_nguoi.* from ConNguoi_nguoi where ma_nguoi='" + Session["id_ntv"] + "'";
            dtt = comm.getDataTable(sql);
            if (dtt.Rows.Count > 0)
            {
                txtTen.Text = dtt.Rows[0]["ho_ten"].ToString();
                dtngaysinh.Text = DateTime.Parse(dtt.Rows[0]["ngay_sinh"].ToString()).ToString("dd-MM-yyyy");
                txtDiaChiChiTiet.Text = dtt.Rows[0]["dia_chi_chi_tiet"].ToString();
                txtDiaChi.Text = comm.execScalar("select dbo.fcGetDiaChiChiTiet ('" + dtt.Rows[0]["dia_chi"] + "')");
                txtMaDiaChi.Value = dtt.Rows[0]["dia_chi"].ToString();
                cboQuocGia.Items.FindByValue(dtt.Rows[0]["quoc_tich"].ToString()).Selected = true;
                cboDanToc.Items.FindByValue(dtt.Rows[0]["dan_toc"].ToString()).Selected = true;
                cboGioiTinh.Items.FindByValue(((Boolean)dtt.Rows[0]["gioi_tinh"] ? "1" : "0")).Selected = true;
                cboHonNhan.Items.FindByValue(((Boolean)dtt.Rows[0]["hon_nhan"] ? "1" : "0")).Selected = true;
                if (!string.IsNullOrEmpty(dtt.Rows[0]["cmnd"].ToString())) txtCMND.Text = dtt.Rows[0]["cmnd"].ToString();
                else txtCMND.Text = "";

                if (!string.IsNullOrEmpty(dtt.Rows[0]["chieu_cao"].ToString())) txtChieuCao.Text = dtt.Rows[0]["chieu_cao"].ToString();
                if (!string.IsNullOrEmpty(dtt.Rows[0]["can_nang"].ToString())) txtCanNang.Text = dtt.Rows[0]["can_nang"].ToString();

                cboSucKhoe.Items.FindByValue(dtt.Rows[0]["suc_khoe"].ToString()).Selected = true;
                txtDienThoaiNha.Text = dtt.Rows[0]["dien_thoai_nha"].ToString();
                txtDiDong.Text = dtt.Rows[0]["dien_thoai_di_dong"].ToString();
                txtTaiKhoanYahoo.Text = dtt.Rows[0]["nick_yahoo"].ToString();
                txtTaiKhoanSkype.Text = dtt.Rows[0]["nick_skype"].ToString();
            }
        }
    }

    #region load comboBox
    protected void LoadTP()
    {
        string sqlComm = "Select ma_dia_chi, ten_dia_chi from DanhMuc_dia_chi where muc=0 order by uu_tien,ten_dia_chi ";
        DataTable dtt = comm.getDataTable(sqlComm);
        for (int i = 0; i < dtt.Rows.Count; i++)
        {
            cbb_tinhthanh.Items.Add(new ListItem(dtt.Rows[i]["ten_dia_chi"].ToString(), dtt.Rows[i]["ma_dia_chi"].ToString()));
        }
    }
    protected void LoadQG()
    {
        string sqlComm = "Select ma_quoc_gia, ten_quoc_gia from DanhMuc_quoc_gia  order by uu_tien,ten_quoc_gia ";
        DataTable dtt = comm.getDataTable(sqlComm);
        for (int i = 0; i < dtt.Rows.Count; i++)
        {
            cboQuocGia.Items.Add(new ListItem(dtt.Rows[i]["ten_quoc_gia"].ToString(), dtt.Rows[i]["ma_quoc_gia"].ToString()));
        }
        //cboQuocGia.SelectedIndex = 0;
    }
    protected void LoadDT()
    {
        string sqlComm = "Select ma_dan_toc, ten_dan_toc from DanhMuc_dan_toc";
        DataTable dtt = comm.getDataTable(sqlComm);
        for (int i = 0; i < dtt.Rows.Count; i++)
        {
            cboDanToc.Items.Add(new ListItem(dtt.Rows[i]["ten_dan_toc"].ToString(), dtt.Rows[i]["ma_dan_toc"].ToString()));
        }
        //cboDanToc.SelectedIndex = 0;
    }
    protected void LoadSK()
    {
        string sqlComm = "Select ma_suc_khoe, ten_suc_khoe from DanhMuc_suc_khoe";
        DataTable dtt = comm.getDataTable(sqlComm);
        for (int i = 0; i < dtt.Rows.Count; i++)
        {
            cboSucKhoe.Items.Add(new ListItem(dtt.Rows[i]["ten_suc_khoe"].ToString(), dtt.Rows[i]["ma_suc_khoe"].ToString()));
        }
        //cboSucKhoe.SelectedIndex = 0;
    }
    #endregion
    protected void Button1_Click(object sender, EventArgs e)
    {
        sql = "Update ConNguoi_nguoi set" +
            " ho_ten=N'" + txtTen.Text + "', ngay_sinh='" + DateTime.ParseExact(dtngaysinh.Text, "dd-MM-yyyy", null).ToString("MM-dd-yyyy") + "'" +
            " ,dia_chi_chi_tiet=N'" + txtDiaChiChiTiet.Text + "',dia_chi='" + txtMaDiaChi.Value + "'" +
            " ,quoc_tich='" + cboQuocGia.SelectedValue + "',dan_toc='" + cboDanToc.SelectedValue + "'" +
            " ,gioi_tinh=" + cboGioiTinh.SelectedValue + ",hon_nhan=" + cboHonNhan.SelectedValue +
            " ,cmnd='" + txtCMND.Text + "'" +
            " ,chieu_cao=" + Decimal.Parse(txtChieuCao.Text == "" ? "0" : txtChieuCao.Text) +
            " ,can_nang=" + Decimal.Parse(txtCanNang.Text == "" ? "0" : txtCanNang.Text) +
            " ,suc_khoe='" + cboSucKhoe.SelectedValue + "',dien_thoai_nha='" + txtDienThoaiNha.Text + "'" +
            " ,dien_thoai_di_dong='" + txtDiDong.Text + "',nick_yahoo='" + txtTaiKhoanYahoo.Text + "'" +
            " ,nick_skype='" + txtTaiKhoanSkype.Text + "'" +
            " where ma_nguoi='" + Session["id_ntv"].ToString() + "'";
        //mess = sql;
        int i = comm.execNoneQuery(sql);
        Response.Redirect("nguoitimviec_detail.aspx?id="+Session["id_ntv"].ToString());
    }
}
